package com.example.demo.concurrent;

import java.util.concurrent.TimeUnit;

/**
 * volatile可见性
 * 
 * @author MI
 *
 */
public class VolatileTest {
	volatile boolean b = true;

	void m() {
		System.out.println("start");
		while (b) {
		}
		System.out.println("end");
	}

	public static void main(String[] args) {
		VolatileTest volatileTest = new VolatileTest();
		new Thread(new Runnable() {
			@Override
			public void run() {
				volatileTest.m();
			}
		}).start();

		try {
			TimeUnit.SECONDS.sleep(1);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		volatileTest.b = false;
	}
}
